package controller.utils;

import javax.faces.bean.ManagedBean;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import model.entities.Group;

@ManagedBean(name="groupConverter")
public class GroupsConverter  implements Converter {

	
	@Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
		System.out.println("before conversion " + value);
		if(value != null)
		{
			return ((Group)value).getGroupId().toString();	
		}
		return "" ;
    }
	
	@Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
		System.out.println("before conversion2 " + value);
		if(value != null){
        return SelectGroupsUtils.findValueByStringConversion(context, component, value, this);
		}
		Group group = null ;
		return group ; 
    }
	
}

